<!DOCTYPE html>
<html>

<head>

    <meta charset="UTF-8">

</head>

<body>

    <div>

        <input type="submit" value="Start" onclick="startSendDataToServer()" />

    </div>

    <div id="messages"></div>

    <script type="text/javascript">


        //var webSocket =  new WebSocket('ws://localhost:9100/websocket?userid=admin');

        var webSocket =  new WebSocket('ws://localhost:9100');



        webSocket.onerror = function(event) {

            onError(event)

        };



        webSocket.onopen = function(event) {

            onOpen(event)

        };



        webSocket.onmessage = function(event) {

            onMessage(event)

        };



        function onMessage(event) {

            document.getElementById('messages').innerHTML

                += '<br />Get Message From Server: ' + event.data;

        }



        function onOpen(event) {

            document.getElementById('messages').innerHTML= 'Connection established';

        }



        function onError(event) {

            alert(event.data);

            alert("error");

        }



        function startSendDataToServer() {
            webSocket.send('hello');
            return false;

        }

    </script>

</body>

</html>